package cn.hy.机考.part03;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @author hy
 * <p>
 * 二十七、考勤问题
 * 公司用一个字符串来标识员工的出勤信息
 * absent: 缺勤
 * late: 迟到
 * leaveearly:早退
 * present: 正常上班
 * <p>
 * 能获得出勤奖的条件如下:缺勤不超过一次; 没有连续的迟到/早退; 任意连续 7 次考勤，缺勤/迟到/早退不超过 3 次\
 * 2
 * present
 * present absent present present leaveearly present absent
 * 输出描述:根据考勤数据字符串，如果能得到考勤奖，输出"true";否则输出 "false"，对于输入示例的结果应为:
 * true false
 */
public class Demo27 {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int num = sc.nextInt();
            sc.nextLine();

            String[] records = new String[num];
            for (int i = 0; i < num; i++) {
                records[i] = sc.nextLine();
            }
            //用list来储存结果
            List<String> list = new ArrayList<>();
            for (String record : records) {
                list.add(String.valueOf(judge(record.split(" "))));
            }

            System.out.println(String.join(" ", list));
        }
    }

    private static boolean judge(String[] str) {
        //缺勤不超过一次
        for (int i = 0; i < str.length; i++) {
            int count = 0;
            if ("absent".equals(str[i])) {
                count++;
            }
            if (count > 1) {
                return false;
            }
        }
        //没有连续迟到早退
        for (int i = 1; i < str.length; i++) {
            String yesterday = str[i - 1];
            String today = str[i];
            if (("leavearly".equals(yesterday) || "late".equals(yesterday)) &&
                    ("leaveearly".equals(today) || "late".equals(today))) {
                return false;
            }
        }
        //连续七次考勤，迟到早退缺勤不超过三次
        if (str.length >= 7) {
            for (int i = 0; i < str.length; i++) {
                int count = 0;
                if (i + 7 > str.length) {
                    break;
                }
                for (int j = i; j < i + 7; j++) {
                    String today = str[j];
                    if ("absent".equals(today) || "late".equals(today) ||
                            "leaveearly".equals(today)) {
                        count++;
                        if (count >= 3) {
                            return false;
                        }
                    }

                }
            }
        }
        return true;
    }
}
